<?php
/**
 * Created by PhpStorm.
 * User: sunwenxu
 * Date: 2019/6/20
 * Time: 12:48
 */

namespace app\common\lib;


use MongoDB\Client;

class ZhyxMongo
{
    public $connection = "";
    private static $instance = null;

    public static function getInstance(): ?ZhyxMongo
    {
        if (self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    final private function __construct()
    {
        $mongoDbConfig = config("database.connections.mongodb");
        $this->connection = (new Client($mongoDbConfig["dsn"]));
    }


    final public function __clone()
    {
        // TODO: Implement __clone() method.
    }


    public function setCollection(string $collectionName, string $databaseName = 'ltfy_tumour'): \MongoDB\Collection
    {
        return $this->connection->selectCollection($databaseName, $collectionName);
    }

}
